package stalker.room.roomusers;

import java.util.ArrayList;
import java.util.List;

import stalker.Stalker;
import stalker.room.RoomAction;

public class PrivateRoomUsers extends RoomUsers {
  
private final List<Stalker> registered_stalkers_;
  
  private void checkRep() {
    assert (registered_stalkers_ != null) :
      "RoomUsers: fields must not be null";
  }
  
  /**
   * Constructs an empty set of users
   */
  public PrivateRoomUsers() {
    registered_stalkers_ = new ArrayList<Stalker>();
    
    checkRep();
  }
  
  /**
   * Mutate this by registering a stalker to the room associated with this.
   * @requires stalker not null
   * @param stalker A stalker that will be registered to this set
   */
  @Override
  public void addUser(Stalker stalker) {
    assert stalker != null;
    registered_stalkers_.add(stalker);
    checkRep();
  }
  
  @Override
  public void removeUser(Stalker stalker) {
    assert stalker != null;
    registered_stalkers_.remove(stalker);
    checkRep();
  }
  
  /**
   * Checks if the selected stalker has the required previlidge to do an action
   * @requires both parameters not null
   * @param stalker   The stalker that requests the action
   * @param action An action that user requests to do
   * @return true iff stalker is registered in this set
   */
  public boolean isAuthorized(Stalker stalker, RoomAction action) {
    assert (stalker != null && action != null);
    if (action.equals(RoomAction.kRegister) && stalker.equals(Stalker.ROOM_MANAGER_STALKER)) {
      return true;
    }
    return registered_stalkers_.contains(stalker);
  }
  
  @Override
  public String toString() {
    return registered_stalkers_.toString();
  }

  @Override
  public List<Stalker> getMembers() {
    return registered_stalkers_;
  }
  
}
